﻿using System;
using log4net;

namespace Cluster
{
    public partial class ClusterManager
    {
        private readonly ILog log = LogManager.GetLogger(typeof(ClusterManager));

        private void Debug(string format, params object[] args)
        {
            if (log.IsDebugEnabled)
            {
                log.DebugFormat(InstanceDescription + format, args);
            }
        }

        private void Info(string format, params object[] args)
        {
            if (log.IsInfoEnabled)
            {
                log.InfoFormat(InstanceDescription + format, args);
            }
        }

        private void Warn(string format, params object[] args)
        {
            if (log.IsWarnEnabled)
            {
                log.WarnFormat(InstanceDescription + format, args);
            }
        }

        private void WarnEx(string format, Exception e)
        {
            if (log.IsWarnEnabled)
            {
                log.Warn(InstanceDescription + format, e);
            }
        }

        private void Error(string format, params object[] args)
        {
            if (log.IsErrorEnabled)
            {
                log.ErrorFormat(InstanceDescription + format, args);
            }
        }

        private void ErrorEx(string format, Exception e)
        {
            if (log.IsErrorEnabled)
            {
                log.Error(InstanceDescription + format, e);
            }
        }

        private string InstanceDescription
        {
            get
            {
                return SelfNode != null ?
                string.Format("[{0} ({1})] ", SelfNode.ZkPath, SelfNode.Name) :
                string.Empty;
            }
        }
    }
}
